home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / Text / prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-08  |  4.1 KB  |  207 lines

  1. /*
  2.  *  Copyright (c) 1993 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10.  
  11. #include <dos/dos.h>
  12.  
  13. #include <intuition/intuition.h>
  14. #include <intuition/screens.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <libraries/gadtools.h>
  17. #include <libraries/asl.h>
  18. #include <graphics/text.h>
  19.  
  20. #include <clib/exec_protos.h>
  21. #include <clib/intuition_protos.h>
  22. #include <clib/dos_protos.h>
  23. #include <clib/gadtools_protos.h>
  24. #include <clib/asl_protos.h>
  25.  
  26. #include <string.h>
  27.  
  28. #include "/Garshnelib/Garshnelib_protos.h"
  29. #include "/Garshnelib/Garshnelib_pragmas.h"
  30.  
  31. #include "Text.h"
  32. #include "Text_rev.h"
  33. #include "//defs.h"
  34. #include "/main.h"
  35.  
  36. struct ModulePrefs
  37. {
  38.     LONG Mode;
  39.     LONG Delay;
  40.     LONG Cycle;
  41.     BYTE Text[128];
  42.     BYTE fName[64];
  43.     struct TextAttr Font;
  44. };
  45.  
  46. struct ModulePrefs nP;
  47. VOID *OldPrefs = 0L;
  48. STATIC const UBYTE VersTag[] = VERSTAG;
  49.  
  50. int BT_SAVEClicked( VOID )
  51. {
  52.     if( OldPrefs )
  53.     {
  54.         CopyMem( &nP, OldPrefs, sizeof( struct ModulePrefs ));
  55.         SavePrefs( OldPrefs );
  56.         OldPrefs = 0L;
  57.     }
  58.     
  59.     return QUIT;
  60. }
  61.  
  62. int BT_TESTClicked( VOID )
  63. {
  64.     MessageServer( BM_SENDBLANK );
  65.  
  66.     return OK;
  67. }
  68.  
  69. int BT_SCREENClicked( VOID )
  70. {
  71.     ScreenModeRequest( TextWnd, &nP.Mode, 0L );
  72.     
  73.     return OK;
  74. }
  75.  
  76. int BT_CANCELClicked( VOID )
  77. {
  78.     OldPrefs = 0L;
  79.     
  80.     return QUIT;
  81. }
  82.  
  83. int SL_DELAYClicked( VOID )
  84. {
  85.     nP.Delay = TextMsg.Code;
  86.  
  87.     return OK;
  88. }
  89.  
  90. int CY_CYCLEClicked( VOID )
  91. {
  92.     nP.Cycle = TextMsg.Code;
  93.  
  94.     return OK;
  95. }
  96.  
  97. int BT_FONTClicked( VOID )
  98. {
  99.     struct FontRequester *fReq;
  100.     struct Library *AslBase;
  101.  
  102.     if(!( AslBase = OpenLibrary( "asl.library", 37L )))
  103.         return OK;
  104.     fReq = AllocAslRequestTags( ASL_FontRequest, ASL_FontName, ( LONG )nP.fName,
  105.                                ASL_FontHeight, nP.Font.ta_YSize, ASL_MaxHeight, 100, TAG_DONE );
  106.     if( fReq )
  107.     {
  108.         if( AslRequestTags( fReq, ASLFO_Window, TextWnd, ASLFO_SleepWindow, TRUE, ASLFO_TitleText,
  109.                            ( LONG )"Please choose a font...", 0L ))
  110.         {
  111.             CopyMem( fReq->fo_Attr.ta_Name, nP.fName, 31 );
  112.             nP.Font.ta_YSize = fReq->fo_Attr.ta_YSize;
  113.         }
  114.         FreeAslRequest( fReq );
  115.     }
  116.     CloseLibrary( AslBase );
  117.  
  118.     return OK;
  119. }
  120.  
  121. int ST_TXTClicked( VOID )
  122. {
  123.     strcpy( nP.Text, GetString( TextGadgets[GD_ST_TXT] ));
  124.         
  125.     return OK;
  126. }
  127.  
  128. #define BL_SetGadgetAttrs( Gad, Tag, Val ) GT_SetGadgetAttrs( TextGadgets[Gad], TextWnd, 0L, Tag, Val, TAG_END )
  129.  
  130. int TextVanillaKey( VOID )
  131. {
  132.     switch( TextMsg.Code ) {
  133.     case 's':
  134.         return BT_SAVEClicked();
  135.     case 't':
  136.         return BT_TESTClicked();
  137.     case 'd':
  138.         return BT_SCREENClicked();
  139.     case 'c':
  140.         return QUIT;
  141.     case 'f':
  142.         return BT_FONTClicked();
  143.     case 'l':
  144.         BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, Inc( nP.Delay, 1, 120 ));
  145.         return OK;
  146.     case 'L':
  147.         BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, Dec( nP.Delay, 1, 0 ));
  148.         return OK;
  149.     case 'r':
  150.         ActivateGadget( TextGadgets[GD_ST_TXT], TextWnd, 0L );
  151.         return OK;
  152.     default:
  153.         return OK;
  154.     }
  155. }
  156.  
  157. #define ComputeX( x ) ((( FontX * x ) + 4 ) / 8 )
  158. #define ComputeY( x ) ((( FontY * x ) + 4 ) / 8 )
  159.  
  160. VOID DoPrefs( LONG command, VOID *Prefs )
  161. {
  162.     switch( command )
  163.     {
  164.     case STARTUP:
  165.         OldPrefs = Prefs;
  166.         CopyMem( Prefs, &nP, sizeof( struct ModulePrefs ));
  167.         if( !SetupScreen())
  168.         {
  169.             TextLeft = ( Scr->Width - ComputeX( TextWidth ))/2 - Scr->WBorRight;
  170.             TextTop = ( Scr->Height - ComputeY( TextHeight ) - Font->ta_YSize )/2 - Scr->WBorBottom;
  171.             if( !OpenTextWindow())
  172.             {
  173.                 BL_SetGadgetAttrs( GD_SL_DELAY, GTSL_Level, nP.Delay );
  174.                 BL_SetGadgetAttrs( GD_CY_CYCLE, GTCY_Active, nP.Cycle );
  175.                 BL_SetGadgetAttrs( GD_ST_TXT, GTST_String, nP.Text );
  176.             }
  177.             CloseDownScreen();
  178.         }
  179.         break;
  180.     case IDCMP:
  181.         if( HandleTextIDCMP() != QUIT )
  182.             break;
  183.     case KILL:
  184.         CloseTextWindow();
  185.         break;
  186.     }
  187. }
  188.  
  189. LONG WndSignal( VOID )
  190. {
  191.     return TextWnd ? 1L << TextWnd->UserPort->mp_SigBit : 0L;
  192. }
  193.  
  194. VOID FillDefaults( VOID *Prefs )
  195. {
  196.     struct ModulePrefs *NewPrefs = ( struct ModulePrefs * )Prefs;
  197.  
  198.     NewPrefs->Mode = getTopScreenMode();
  199.     NewPrefs->Delay = 60L;
  200.     NewPrefs->Cycle = 0L;
  201.     NewPrefs->Font.ta_YSize = 11;
  202.     NewPrefs->Font.ta_Style = FS_NORMAL;
  203.     NewPrefs->Font.ta_Flags = FPB_ROMFONT;
  204.     strcpy( NewPrefs->fName, "topaz.font" );
  205.     strcpy( NewPrefs->Text, "Every good boy deserves fudge." );
  206. }
  207.